package work.timejay.shop.controller.shop;


import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import work.timejay.common.ApiPageEntity;
import work.timejay.common.ApiResult;
import work.timejay.dto.shop.ShopOperationDTO;
import work.timejay.dto.shop.ShopSearchDTO;

import work.timejay.enums.ErrorMsg;
import work.timejay.exception.TimeJayException;
import work.timejay.shop.entity.shop.Shop;
import work.timejay.shop.service.shop.ShopService;
import work.timejay.vo.shop.ShopInfoVO;
import work.timejay.vo.shop.ShopItemVO;

/**
 * <p>
 * 项目表 前端控制器
 * </p>
 *
 * @author 王文杰
 * @since 2024-02-05
 */
@RestController
@RequestMapping("/api/shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    /**
     * 商品分页
     */
    @PostMapping(value = "/page")
    @SaIgnore
    private ApiPageEntity<ShopItemVO> pages(@RequestBody ShopSearchDTO<Shop> dto) {
        return shopService.shopPages(dto);
    }

    /**
     * 商品详情
     */
    @GetMapping(value = "/{id}")
    @SaIgnore
    public ApiResult<ShopInfoVO> info(@PathVariable(value = "id") String id) {
        ShopInfoVO vo = shopService.findInfoById(id);
        return ApiResult.success(vo);
    }

    /**
     * 商品点赞关注分享
     */
    @PutMapping(value = "/operation")
    public ApiResult<Void> operation(@RequestBody @Validated ShopOperationDTO dto){
        shopService.operation(dto);
        return ApiResult.success();
    }
}

